local juelie = fk.CreateSkill {
  name = "juelie",
}

juelie:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      local room = player.room
      return not data.chain and (table.every(room.alive_players, function (p)
        return p:getHandcardNum() >= player:getHandcardNum()
      end) or table.every(room.alive_players, function (p)
        return p.hp >= player.hp
      end))
    end
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
})


juelie:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
      local to = data.to
      return not to.dead and not player:isNude()
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 1, 999, true, self.name, true, ".", "#juelie-discard::"..data.to.id, true)
    if #cards > 0 then
      event:setCostData(self,cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.simpleClone(event:getCostData(self))
    room:throwCard(cards, self.name, player, player)
    local to = data.to
    if player.dead or to.dead or to:isNude() then return end
    cards = room:askForCardsChosen(player, to, 1, math.min(#cards, #to:getCardIds("he")), "he", self.name)
    room:throwCard(cards, self.name, to, player)
  end,
})

return juelie